var str = "/a/b"; // ['/a', '/a/b']

var arr = str.split("/").filter((item) => item);

const newArr = arr.reduce((previousValue, currentValue, currentIndex) => {
  if (currentIndex === 0) {
    previousValue.push(`/${currentValue}`);
  } else {
    previousValue.push(`${previousValue[currentIndex - 1]}/${currentValue}`);
  }
  return previousValue;
}, []);

console.log(newArr);
